// pages/index3/index3.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img1: '../images/image50.png',
    img2: '../images/image48.png',
    num: 1,
    id:'',//店铺账号
    ishidden: false,
    array: ['餐饮美食/杭帮菜', '杭帮菜', '餐饮美食/杭帮菜', '餐饮美食/杭帮菜'],
    address: "标注后有利于引导客源",
    leader_name:'',
    leader_id_card:'',
    name:'',
    business_licence_no:'',
    leader_id_card_image:'',
    business_licence_image:'',
  },
  // 获取名称
  getName(e){
    let that = this;
    that.setData({ leader_name:e.detail.value})
  },
  getId(e) {
    let that = this;
    that.setData({ leader_id_card: e.detail.value })
  },
  getQiYe(e) {
    let that = this;
    that.setData({ name: e.detail.value })
  },
  getYyzz(e) {
    let that = this;
    that.setData({ business_licence_no: e.detail.value })
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value,
      ishidden: true
    })
  },
  gomap: function (e) {
    wx.navigateTo({
      url: '../map/map'
    })
  },
  shows(msg){
    wx.showToast({
      title: msg,
      icon:'warning'
    })
  },
  // 提交实名认证
  formSubmit(e){
    let that = this;
    let form = e.detail.value;
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (!form.leader_name){
      that.shows("请输入姓名")
      return;
    }
    if (!form.leader_id_card) {
      that.shows("请输入身份证号")
      return;
    }
    if (!reg.test(form.leader_id_card)){
      that.shows("请输入正确身份证号")
      return;
    }
    if (!form.name) {
      that.shows("请输入企业名称")
      return;
    }
    if (!form.business_licence_no) {
      that.shows("请输入营业执照注册号")
      return;
    }
    if (that.data.img1 == "../images/image50.png") {
      that.shows("请上传身份证照片")
      return;
    }
    if (that.data.img2 == "../images/image48.png") {
      that.shows("请上传营业执照照片")
      return;
    }
    
    let postData = {
      leader_id_card_image: that.data.img1,
      business_licence_image: that.data.img2,
      ...form
    };
    app.post("/personal/real_name","post",postData).then(res =>{
      that.shows(res.msg)
      setTimeout(function(){
        wx.navigateBack({
          delta: -1
        });
      }, 1000);
    })
  },
  // 点击取消
  QuXiao(){
    wx.navigateBack({
      delta: -1
    });
  },
  //上传照片
  clickImg: function (e) {
    let that = this;
    var me = this;
    wx.chooseImage({
      count: 1,
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: 'https://api.51huijingang.com/api/merchant/upload', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: "file",
          success: function (data) {
            var datas = JSON.parse(data.data);
            console.log(datas)
            var datass = datas.url
            that.setData({ img1: datass })
          }
        })
      },
    })
  },
  //上传营业执照
  clickImg1: function (e) {
    let that = this;
    wx.chooseImage({
      count: 1,
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: 'https://api.51huijingang.com/api/merchant/upload', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: "file",
          success: function (data) {
            var datas = JSON.parse(data.data);
            console.log(datas)
            var datass = datas.url
            that.setData({ img2: datass })
          }
        })
      }
    })
  },

  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    let that = this;
    that.setData({id:e.id})

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})